fix(gui): handle invalid file name edge case on Windows
authorJyrki Gadinger <nilsding@nilsding.org>
Thu, 17 Apr 2025 16:00:09 +0000 (18:00 +0200)
committerMatthieu Gallien <matthieu.gallien@nextcloud.com>
Fri, 30 May 2025 07:39:56 +0000 (09:39 +0200)
File names like "c:blah" would break the usage of the dialogue,
displaying a path like "c://blah" instead.

Apparently `QDir::filePath` checks if the passed file name is an
absolute file name using `!QFileInfo::isRelative`, which is the case if
the second character in the string is a colon -- probably indicating a
drive letter.

Signed-off-by: Jyrki Gadinger <nilsding@nilsding.org>
src/gui/tray/activitylistmodel.cpp

index b39b354c44e71debfcd4e609ab04d7d511ad9046..9bd40185972f6571cfdb22dcfcb93731b581547c 100644 (file)
@@ -694,8 +694,21 @@ void ActivityListModel::slotTriggerDefaultAction(const int activityIndex)
             ? InvalidFilenameDialog::InvalidMode::ServerInvalid
             : InvalidFilenameDialog::InvalidMode::SystemInvalid;
 
+#ifdef Q_OS_WIN
+        // Edge case time!
+        // QDir::filePath checks whether the passed `fileName` is absolute (essentialy by using `!QFileInfo::isRelative()`).
+        // On Windows, if `fileName` starts with a letter followed by a colon (e.g. "A:BCDEF"), it is considered to be an
+        // absolute path.
+        // Since the complete desired path is required by InvalidFilenameDialog, catch that special case here and prefix it ourselves...
+        const auto filePath = activity._file.length() >= 2 && activity._file[1] == ':'
+                              ? folder->path() + activity._file
+                              : folderDir.filePath(activity._file);
+#else
+        const auto filePath = folderDir.filePath(activity._file);
+#endif
+
         _currentInvalidFilenameDialog = new InvalidFilenameDialog(_accountState->account(), folder,
-            folderDir.filePath(activity._file), fileLocation, invalidMode);
+            filePath, fileLocation, invalidMode);
         connect(_currentInvalidFilenameDialog, &InvalidFilenameDialog::accepted, folder, [folder]() {
             folder->scheduleThisFolderSoon();
         });